package com.imooc.subscribe;

import com.imooc.entity.User;
import com.imooc.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

/**
 * implements ApplicationRunner, Ordered 是实现 线程的一种方式 当然你也可以 继承 runnable
 * CommandLineRunner也可以在spring启动的时候进行执行
 */
@Slf4j
@Component
public class UserSubscriber implements ApplicationRunner, Ordered {
    @Override
    public void run(ApplicationArguments args) {
        log.info("线程正在运行 --");
        RedisUtil.subscribe("user", User.class, (user) -> {
            log.info(user.getName() + ":" + user.getAge());
        });
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
